### Alizade, Dancygier, Ditlmann
### "National Penalties Reversed"
### Replication Code 
### Table 1
### For questions, contact jalizade@princeton.edu

# setup
rm(list=ls())
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")
library(XLConnect)
tab <- readWorksheetFromFile("data_studies.xlsx", sheet=1)

# create table
domains <- c("bureaucrats", "housing market", "labor market", "politicians")
n <- sapply(domains, function(x) sum(grepl(x, tab$Domain)))
lower <- sapply(domains, function(x) sum(tab$Effect.of.Lower.Status.Group.on.Callback.Response.Rate=="-" & 
                                         grepl(x, tab$Domain)))
same <- sapply(domains, function(x) sum(tab$Effect.of.Lower.Status.Group.on.Callback.Response.Rate=="0" & 
                                        grepl(x, tab$Domain)))
higher <- rep(0, 4)

sumtab <- data.frame(n, lower, same, higher)
sumtab$lower <- round((sumtab$lower/sumtab$n)*100)
sumtab$same <- round((sumtab$same/sumtab$n)*100)
sumtab[,2:4] <- sapply(2:4, function(x) paste0(sumtab[,x], "%"))
sumtab <- sumtab[c(3,2,1,4),]
sumtab